package com.zhang.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.mapper.IProductMapper;
import com.zhang.pojo.ProductBean;
import com.zhang.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class ProductServiceImpl implements IProductService {

    @Autowired
    private IProductMapper productMapper;


    @Override
    public PageInfo<ProductBean> findByItem(int pageNo, String status ,String name, LocalDate start, LocalDate end) {
        PageHelper.startPage(pageNo,4);
        PageInfo<ProductBean> pageInfo = PageInfo.of(productMapper.findByItem(name, status,start, end));
        return pageInfo;
    }

    @Override
    public ProductBean findById(int id) {
        return productMapper.findById(id);
    }

    @Override
    public void add(ProductBean productBean) {
        productMapper.add(productBean);
    }

    @Override
    public void update(int productId, String status, Integer price) {
        productMapper.update(productId, status, price);
    }
}
